package cn.devzyh.service.impl;

import cn.devzyh.dao.CourseContentMapper;
import cn.devzyh.domain.CourseLesson;
import cn.devzyh.domain.CourseSection;
import cn.devzyh.service.CourseContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CourseContentServiceImpl implements CourseContentService {

    @Autowired
    private CourseContentMapper courseContentMapper;

    @Override
    public List<CourseSection> findSectionAndLesson(Integer id) {

        return courseContentMapper.findSectionAndLesson(id);
    }

    @Override
    public void saveSection(CourseSection section) {

        Date now = new Date();
        section.setCreateTime(now);
        section.setUpdateTime(now);
        courseContentMapper.saveSection(section);
    }

    @Override
    public void updateSection(CourseSection section) {

        section.setUpdateTime(new Date());
        courseContentMapper.updateSection(section);
    }

    @Override
    public void updateSectionStatus(Integer id, Integer status) {

        CourseSection section = new CourseSection();
        section.setId(id);
        section.setStatus(status);
        section.setUpdateTime(new Date());
        courseContentMapper.updateSectionStatus(section);
    }

    @Override
    public void saveLesson(CourseLesson lesson) {

        Date now = new Date();
        lesson.setCreateTime(now);
        lesson.setUpdateTime(now);
        courseContentMapper.saveLesson(lesson);
    }

    @Override
    public void updateLesson(CourseLesson lesson) {

        lesson.setUpdateTime(new Date());
        courseContentMapper.updateLesson(lesson);
    }
}
